package sat.component;

import org.mt4j.MTApplication;
import org.mt4j.components.TransformSpace;
import org.mt4j.components.visibleComponents.shapes.MTRectangle;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;
import org.mt4jx.components.visibleComponents.widgets.toolbar.MTLayoutContainer;

/*
 * This class' children are all tabs.
 * Add non-tab type child will cause some errors
 */

public class ToolbarTabArray extends MTRectangle{

	private MTApplication app;
	private Toolbar toolBar;
	private int tabNb = 0;  // the tabs will be automatically added 
	
	/*
	 * outLine the tab by name and change the container to the one associated with the tab
	 */
	public void selectTabByName(String tabName){
		ToolbarTab tab = (ToolbarTab)this.getChildByName(tabName);
		tab.setSelected();
		this.toolBar.changeCurrentContainer(tab.getContainer());
	}
	
	public void setAllUnselected(){
		for (int i = 0; i < this.getChildCount(); i++) {
			ToolbarTab temp = (ToolbarTab) this.getChildByIndex(i);
			temp.setUnselected();
		}
	}
		
	public void addTab(MTLayoutContainer container, String tabName){
		
		ToolbarTab tab = new ToolbarTab(app,toolBar,Toolbar.tabListWidth/(tabNb+1),Toolbar.tabListHeight-1,tabName);
		tab.setContainer(container);
		this.addChild(tab);
		this.toolBar.addChild(container);
		container.setVisible(false); 
		// hide all the specific container, only the currentContainer is explicitly used.
		// Only the invisible containers are available.
		
		tabNb++;
		
		for (int i = 0; i < tabNb; i++) {
			ToolbarTab temp = (ToolbarTab) this.getChildByIndex(i);
			temp.setWidthLocal(Toolbar.tabListWidth/(tabNb));
			
			// add a tab in line on the same vertical level
			temp.setPositionRelativeToParent(new Vector3D(
					(Toolbar.tabListWidth+10)/(tabNb)*(0.5f+i)-1,
					temp.getPosition(TransformSpace.RELATIVE_TO_PARENT).y
					));
		}
	}
	
	public ToolbarTabArray(MTApplication mtApplication,Toolbar tb,float width, float height) {
		super(mtApplication, 0, 0, 0, width, height);
		this.app = mtApplication;
		this.toolBar = tb;
		this.setFillColor(MTColor.BLACK);
		//this.unregisterAllInputProcessors(); //Remove the default drag, rotate and scale gestures first
		//this.removeAllGestureEventListeners(RotateProcessor.class);
		//		this.removeAllGestureEventListeners(ScaleProcessor.class);
	}
}
